import React from 'react';
import PropTypes from 'prop-types';
const isRequired = {
  required: true,
  message: '必填',
};
const ValidRules = (type) => {
  switch (type) {
    case 'phone':
      return [
        isRequired,
        {
          pattern: /^1[345789]\d{9}$/,
          message: '手机号格式不正确',
        },
      ];
    case 'idCard':
      return [
        isRequired,
        {
          pattern:
            /^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/,
          message: '身份证格式不正确',
        },
      ];
    case 'creditCode':
      return [
        isRequired,
        {
          message: '税号长度必须是18位',
          len: 18,
        },
      ];
    case 'email':
      return [
        isRequired,
        {
          pattern:
            /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/,
          message: '邮箱格式不正确',
        },
      ];
    case 'null':
      return [isRequired];
    case 'number':
      return [
        isRequired,
        {
          required: true,
          pattern: /^\+?[1-9][0-9]*$/,
          message: '请输入正确的数字',
        },
      ];
    case 'name':
      return [
        isRequired,
        {
          required: true,
          pattern: /^[\u2E80-\u9FFF]+$/,
          message: '请输入汉字姓名',
        },
      ];
    case 'newName':
      return [
        isRequired,
        {
          required: true,
          pattern: /[0-9a-zA-Z]|[\u4e00-\u9fa5]/im,
          message: '不能输入特殊符号',
        },
      ];
    default:
      return;
  }
};
ValidRules.propTypes = {
  type: PropTypes.string,
};

// 使用直接传入类型的字符串  ValidRules('phone')
export default ValidRules;
